package com.apware.utils.config;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger; 

/**
 * 
 * @author
 * 
 */
public class Config {

	public static final String JINGRIU = "jingrui";
	public static final String PENGYU = "pengyu";
	public static final String weidechuangjian = "weidechuangjian";
	public static final String shide = "shide";
	
	private static Logger log = Logger.getLogger(Config.class);

	public static int timerInterval; 
	public static String requestUrl;
	public static String supplierCode;
	public static String dbName;
	public static String exportedFile;

	public static String erp = "chaoyue";

	/**
	 * 读取配置文件
	 * 
	 * @throws ConfigurationException
	 */
	public static boolean readConfig() {
		Properties prop = new Properties();
		
		/**
		 * 获取绝对路径
		 */
		try {
			
			InputStream istream  = new FileInputStream("conf/config.properties");
			prop.load(istream);
			istream.close();
			timerInterval = Integer.valueOf(prop.getProperty("timerInterval").trim());
			requestUrl = prop.getProperty("requestUrl").trim(); 
			supplierCode = prop.getProperty("supplierCode").trim(); 
			dbName = prop.getProperty("dbpoolName").trim(); 
			exportedFile = prop.getProperty("exportedFile")!=null?prop.getProperty("exportedFile").trim():null; 
			erp = prop.getProperty("erp")!=null?prop.getProperty("erp").trim():null;
			log.info("erp is:" + erp);
			if(!"jingrui".equals(erp))
				log.info("reading data from database:"+ dbName);
			log.info("supplier:" + supplierCode 
					+ " and result will be posted to:" + requestUrl);
			return true;

		} catch (Exception e) {
			log.error("加载配置失败!", e);
			
			return false;
		}
	}

}
